package com.hqyj.springboot.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hqyj.springboot.entity.Students;
import com.hqyj.springboot.mapper.StudentsMapper;
import com.hqyj.springboot.service.StudentsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;

@Service
public class StudentsServiceImpl extends ServiceImpl<StudentsMapper, Students> implements StudentsService {

    @Resource
    private StudentsMapper studentsMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean insertStudents(Students s) throws Exception {
        try {
            studentsMapper.insert(s);
            return true;
        }catch (Exception ex){
            ex.printStackTrace();
            //回滚，手动回滚。。。
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return false;
        }
    }
}
